<?php


namespace app\common\model;


use app\api\library\OrderSn;

class Orders extends BaseModel
{
    protected $table = 'fa_orders';

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';

    protected static function init()
    {
        self::beforeInsert(function ($row){
            $row->order_sn = '';
        });
    }

    public function setOrderSnAttr($value)
    {
        return OrderSn::create();
    }

    public function demand()
    {
        return $this->belongsTo(Demand::class);
    }

    public function goods()
    {
        return $this->belongsTo(Goods::class);
    }

    public function partyA()
    {
        return $this->belongsTo(User::class,'aid');
    }
    public function partyB()
    {
        return $this->belongsTo(User::class,'bid');
    }
}